home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
SOUND
/
SOUNDCON00
/
!SoundCon
/
Docs
/
PlaySample
< prev
Wrap
Text File
|
1995-02-18
|
10KB
|
223 lines
The PlaySample module version 2.41
==================================
by Rick Hudson,
rick@actrix.gen.nz
The PlaySample module is a module that can play samples in a variety of
formats straight from the disc file. It is designed to play samples
accurately at their recorded rate independantly of current sound system
speed and (hopefully) the effects of VIDC enhancers.
The PlaySample module provides a small number of commands and a few SWIs
that can be used to control the playback of samples. It's usual use will be
from the desktop through a program like SoundCon or MTaudio. Command line
use is quite limited as it can only play Armadeus files.
Terminology notes for this text:
- A "sample" is the wave amplitude at a given time for ONE given channel
- A "sample frame" or just "frame" is the set of samples on ALL channels
at a given time. For a mono sound this will mean the same as a sample,
but for a stereo sound there are two samples per sample frame (one for
each channel)
- A "sample file" is the disc file containing samples
- "Sample period" is the time interval between sending sample frames to
the sound system
- "Sample frequency" or "playback frequency" is the rate of sending
sample frames to the sound system. The actual number of bytes per
second will depend on the bits per sample and the number of channels.
Commands:
- SPlay <filename> [<start>]
Start playing the sound in file <filename>. Optionally, the sound
can be started at byte offset <start>. Note that if manual polling is
enabled then *SMore must be used regularly to maintain playback. The
sound must be an Armadeus format file otherwise unpredicable things
will happen. Playing of other formats is only supported through the
SWI interface.
- SStop
Stop the sound playing and release the sound system.
- SPause
Toggle start/stop of sound playback.
- SMore
In manual polling mode, this command must be executed regularly (say
twice a second at least) to maintain playback continuity. If the
buffer 'runs out' then the sound is stopped (equivalent to an
explicit *SPause) until the buffer is refilled. This command has no
effect in automatic polling mode or when no sound is playing.
- SAuto
Switch on automatic polling (see below).
- SManual
Switch off automatic polling (see below).
- SVolume <vol>
Set the volume of PlaySample. <vol> is in the range 1 (quiet) to 127
(loud), the same the system *Volume command. Note that PlaySample uses
a volume setting independant of the system volume so that *Volume will
have no effect on it.
- SSpeed <num>
<num> is a tuning value for PlaySample to allow for the correction of
playback speed when the actual VIDC frequency is different from what
the sound system is expecting. <num> is <expected freq>/<actual freq>
* &10000, eg 24000/25175*&10000 = 62447 will slow the sound down
sightly if it is too fast. The actual frequency can be obtained from
VduVariable &AC in RISC OS (except if it's very old) and the expected
frequency is the nearest multiple of 4000Hz to it. Desktop front ends
should select this automatically.
SWIs:
PlaySample_Status (&CF8C0)
Playback monitors can use this call to determine what the state of the
player is. R2, R4 and R5 can be used to determine the time offset into
the sample using t=R2 / (16e6/R4) / (bits per sample/8*channels).
On entry: -
On Exit: R0 : bit 0 = set if sound is playing
bit 1 = set if sound paused
bit 2 = set if sound finished
bit 3 = set if a sound file is open
bit 4 = set if module has voice claimed
bit 31 = set if manual polling enabled
R1 = pointer to file leafname
R2 = current byte offset into sample file
R3 = size of sample file in bytes
R4 = sample period (microseconds * 16)
R5 = voice mode: bit 0 = set if stereo, clear if mono
bits 1-7: 0 = 8-bit
1 = 16-bit
2 = 4-bit MS ADPCM
3 = 4-bit DVI ADPCM
PlaySample_Open (&CF8C1)
Open a file and define its format. Playback is not started (pause mode
is entered). Use PlaySample_Play to start the playback.
On entry: R0 = pointer to filename to open (0 for current file)
R1 = sample format:
<=0 - 8 bit linear signed
1 - 8 bit linear unsigned
2 - 8 bit mu-law
3 - 8 bit VIDC
4 - 16 bit linear signed little endian
5 - 16 bit linear signed big endian
6 - 16 bit linear unsigned little endian
7 - 16 bit linear unsigned big endian
8 - Microsoft ADPCM
9 - DVI ADPCM
R2 = sample period in microseconds * 16 (if R2=0 and R1=-1,
period obtained from first byte of file). eg for 22050Hz,
R2=16e6/22050 = 727. Default frequency (if R2 is invalid)
is 11111Hz.
R3 = number of channels (<>2 for mono, 2 for stereo).
R4 = file offset of last sample to play + 1. If the file has
'garbage' after the actual sound sample then pointing R4
at the first garbage byte will define the end point. If
R4<=0 playback stops when the end of the file is reached.
if R3<>2 (mono) then
R5 = echo delay in sample periods for simulated stereo
effect (max 2048). R5=(echo time)*(playfrequency), eg
R5 = 0.1secs * 11111Hz = 1111.
if R3=2 (stereo) then
R5 = stereo interleave (bytes left, bytes right, etc). eg 1
for PCM WAVEs, 8 for AudioWorks. This number must be a
power of 2 (ie 1, 2, 4, 8, etc) and the buffer size
must be a multiple of 2*interleave to ensure that a
left/right chunk is always completely in the buffer.
if R1=8 or 9 (ADPCM formats) then
R6 = number of compressed sample frames in block. ie
nFramesPerBlock (bytes &12 and &13 of the WAVE 'fmt '
chunk) - frames in block header. ie nFramesPerBlk-1
for DVI ADPCM and nFramesPerBlock-2 for MS ADPCM.
This call will require knowledge of the file format to fill in all the
registers properly. ADPCM WAVEs in particular need precise information
from the header block. Contact the author if you want more information
on any of the formats supported by SoundCon or if you can supply some
information on any formats it doesn't support!
Note that to play a normal armadeus sample at the default frequency,
R1=-1, R2=R3=R4=0.
PlaySample_SetPtr (&CF8C2)
On entry: R0 = absolute file offset to move to. Used to set the start
position after the file header or for cueing etc.
PlaySample_Play (&CF8C3)
Start playing the sound from the current pointer position.
PlaySample_Stop (&CF8C4)
If a sound is playing, it is stopped and the sound system is freed. No
more playback will be possible until another PlaySample_Open is done.
PlaySample_Pause (&CF8C5)
Stop the sound playing but playback can be restarted with
PlaySample_Play. PlaySample_SetPtr can be called while paused.
PlaySample_Config (&CF8C6)
On entry: R0 = buffer size (0 for no change - default is 8k)
R1 = polling: 0 = no change, 1 = automatic, 2 = manual
On exit: R0 = buffer size
R1 = polling mode
Important note: For playing ADPCM samples, the buffer size MUST be a
multiple of the sample block size. ie size = n*nBlockAlign. For other
samples, the buffer must be a multiple of the number of bytes per frame.
eg for 16 bit stereo, the buffer must be a multiple of 4 bytes.
PlaySample_Volume (&CF8C7)
Set or read the PlaySample volume. Note that PlaySample's volume is
independant of the system volume.
On entry: R0 = volume (0 for no change, 1=quiet, 127=loud)
On exit: R0 = volume setting
PlaySample_Speed (&CF8C8)
Tune Playsample for sound system speed inaccuracies. See the description
of *SSpeed (above) for details.
On entry: R0 = tuning value (<expected freq> / <actual freq> * &10000)
On exit: R0 undefined
PlaySample_Version (&CF8C9)
Return the version number*100 of PlaySample (241 for version 2.41)
On entry: -
On exit: R0 = version number * 100
Note that it is not necessary to stop a sample playing before starting a new
one or killing the module.
Polling mechanism: The normal polling mechanism makes use of OS_AddCallBack
to allow delayed access to disc SWIs from inside the voice generator code.
This may cause problems in RISC OS 2 (although this version seems ok) where
there was a bug in the call back handler. If errors start occurring (like
address exceptions) then first ensure that the IRQUtils module has been
loaded which should fix this problem. If the PlaySample module is still
causing problems then manual polling can be used (software may or may not
allow you to change this).
If the sample stops unexpectedly when playing off a floppy disc, try either
decreasing the buffer size to keep the drive running continuously or
increase it to ensure that enough data is in the memory to cover the time it
takes to restart the floppy from a stop. This is a trial and error thing!